import da from "element-ui/src/locale/lang/da";

const filter = {
    formatDate: function (value, args) {
        var dt = new Date(value);
        if (args == 'yyyy-M-d') {// yyyy-M-d
            let year = dt.getFullYear();
            let month = dt.getMonth() + 1;
            if (month < 10)
                month = '0' + month
            let date = dt.getDate();
            if (date < 10)
                date = '0' + date
            return `${year}-${month}-${date}`;
        } else if (args == 'yyyy-M-d H:m:s') {// yyyy-M-d H:m:s
            let year = dt.getFullYear();
            let month = dt.getMonth() + 1;
            if (month < 10)
                month = '0' + month
            let date = dt.getDate();
            if (date < 10)
                date = '0' + date
            let hour = dt.getHours();
            if (hour < 10)
                hour = '0' + hour
            let minute = dt.getMinutes();
            if (minute < 10)
                minute = '0' + minute
            let second = dt.getSeconds();
            if (second < 10)
                second = '0' + second
            return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
        } else if (args == 'yyyy-MM-dd') {// yyyy-MM-dd
            let year = dt.getFullYear();
            let month = (dt.getMonth() + 1).toString().padStart(2, '0');
            let date = dt.getDate().toString().padStart(2, '0');
            return `${year}-${month}-${date}`;
        } else {// yyyy-MM-dd HH:mm:ss
            let year = dt.getFullYear();
            let month = (dt.getMonth() + 1).toString().padStart(2, '0');
            let date = dt.getDate().toString().padStart(2, '0');
            let hour = dt.getHours().toString().padStart(2, '0');
            let minute = dt.getMinutes().toString().padStart(2, '0');
            let second = dt.getSeconds().toString().padStart(2, '0');
            return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
        }
    },
    secondsToTime: function (second) {
        // ( 总秒数 - 天的秒数 ) / 一小时的秒数
        let h = parseInt(second / 60 / 60);

        // ( 总秒数 - 天的秒数 - 小时的秒数 ) / 一分钟的秒数
        let m = parseInt(second / 60 - h * 60);

        // 总秒数 - 天的秒数 - 小时的秒数 - 分钟的秒数
        let s = second - h * 60 * 60 - m * 60;

        return h + ':' + m + ':' + s
    },
}
export default filter;